package com.hongruan.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.hongruan.bean.Account;
import com.hongruan.common.Constants;
import com.opensymphony.xwork2.ActionSupport;

public class BaseAction extends ActionSupport {
    private static final long serialVersionUID = -8895141755710006385L;
    private static Logger logger = Logger.getLogger(BaseAction.class);
    
    protected HttpServletRequest getRequest() {
        return ServletActionContext.getRequest();
    }

    protected HttpServletResponse getResponse() {
        return ServletActionContext.getResponse();
    }
    
    protected HttpSession getSession() {
        return this.getRequest().getSession();
    }
    
    protected Account getCurrentAccount(){
    	return (Account) getRequest().getSession().getAttribute(Constants.SESSION_USER_KEY);
    }
    
    protected void writeAjaxResult(String s) {
        try {
            this.getResponse().getOutputStream().write(s.getBytes("utf-8"));
        } catch (Exception e) {
            logger.error("ajax output exception");
        }
    }
}
